/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.klikmee.sms.core.model;

import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Date;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 * @author makcro
 */
@Entity
@Table(name = "incomingmessage")
@NamedQueries({
		@NamedQuery(name = "IncomingMessage.findAll", query = "SELECT i FROM IncomingMessage i"),
		@NamedQuery(name = "IncomingMessage.findById", query = "SELECT i FROM IncomingMessage i WHERE i.id = :id"),
		@NamedQuery(name = "IncomingMessage.findByFromNumber", query = "SELECT i FROM IncomingMessage i WHERE i.fromNumber = :fromNumber"),
		@NamedQuery(name = "IncomingMessage.findByToNumber", query = "SELECT i FROM IncomingMessage i WHERE i.toNumber = :toNumber"),
		@NamedQuery(name = "IncomingMessage.findByMessage", query = "SELECT i FROM IncomingMessage i WHERE i.message = :message"),
		@NamedQuery(name = "IncomingMessage.findByProviderMessageId", query = "SELECT i FROM IncomingMessage i WHERE i.providerMessageId = :providerMessageId"),
		@NamedQuery(name = "IncomingMessage.findByState", query = "SELECT i FROM IncomingMessage i WHERE i.state = :state"),
		@NamedQuery(name = "IncomingMessage.findByStateChangeTime", query = "SELECT i FROM IncomingMessage i WHERE i.stateChangeTime = :stateChangeTime"),
		@NamedQuery(name = "IncomingMessage.findByProvidersIncomingTime", query = "SELECT i FROM IncomingMessage i WHERE i.providersIncomingTime = :providersIncomingTime"),
		@NamedQuery(name = "IncomingMessage.findByOurIncomingTime", query = "SELECT i FROM IncomingMessage i WHERE i.ourIncomingTime = :ourIncomingTime"),
		@NamedQuery(name = "IncomingMessage.findByTypeOfMessage", query = "SELECT i FROM IncomingMessage i WHERE i.typeOfMessage = :typeOfMessage"),
		@NamedQuery(name = "IncomingMessage.findByTelenorEuRequest", query = "SELECT i FROM IncomingMessage i WHERE i.telenorEuRequest = :telenorEuRequest"),
		@NamedQuery(name = "IncomingMessage.findByDataCoding", query = "SELECT i FROM IncomingMessage i WHERE i.dataCoding = :dataCoding"),
		@NamedQuery(name = "IncomingMessage.findByTelenorESMC", query = "SELECT i FROM IncomingMessage i WHERE i.telenorESMC = :telenorESMC"),
		@NamedQuery(name = "IncomingMessage.findByMessageBody", query = "SELECT i FROM IncomingMessage i WHERE i.messageBody = :messageBody"),
		@NamedQuery(name = "IncomingMessage.findByUrl", query = "SELECT i FROM IncomingMessage i WHERE i.url = :url"),
		@NamedQuery(name = "IncomingMessage.findByStateAndProvider", query = "SELECT im FROM IncomingMessage im WHERE im.state = :state AND im.provider.name = :provider"),
		@NamedQuery(name = "IncomingMessage.findByStateAndService", query = "SELECT im FROM IncomingMessage im WHERE im.state = :state AND im.service = :service") })
public class IncomingMessage implements Serializable {

	private static final long	serialVersionUID	= 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Basic(optional = false)
	@Column(name = "Id", nullable = false)
	private Long				id;
	@Basic(optional = false)
	@Column(name = "FromNumber", nullable = false, length = 100)
	private String				fromNumber;
	@Basic(optional = false)
	@Column(name = "ToNumber", nullable = false, length = 100)
	private String				toNumber;
	@Column(name = "Message", length = 1000)
	private String				message;
	@Column(name = "ProviderMessageId", length = 100)
	private String				providerMessageId;
	@Column(name = "MtsSessionId", length = 256)
	private String				mtsSessionId;
	@Column(name = "State")
	private Integer				state;
	@Column(name = "StateChangeTime")
	@Temporal(TemporalType.TIMESTAMP)
	private Date				stateChangeTime;
	@Column(name = "ProvidersIncomingTime")
	@Temporal(TemporalType.TIMESTAMP)
	private Date				providersIncomingTime;
	@Column(name = "ourIncomingTime")
	@Temporal(TemporalType.TIMESTAMP)
	private Date				ourIncomingTime;
	@Column(name = "TypeOfMessage")
	private Integer				typeOfMessage;
	@Column(name = "TelenorEuRequest", length = 100)
	private String				telenorEuRequest;
	@Column(name = "DataCoding", length = 100)
	private String				dataCoding;
	@Column(name = "TelenorESMC", length = 100)
	private String				telenorESMC;
	@Column(name = "MessageBody", length = 100)
	private String				messageBody;
	@Column(name = "Url", length = 1000)
	private String				url;
	@Lob
	@Column(name = "Data")
	private byte[]				data;
	@OneToMany(mappedBy = "incomingMessage", fetch = FetchType.EAGER)
	private Set<PaymentInvoice>	paymentInvoiceList;
	@JoinColumn(name = "Provider", referencedColumnName = "id", nullable = false)
	@ManyToOne(optional = false)
	private Provider			provider;
	@JoinColumn(name = "Service", referencedColumnName = "Id")
	@ManyToOne
	private Service				service;

	public IncomingMessage() {
	}

	public IncomingMessage( Long id ) {
		this.id = id;
	}

	public IncomingMessage( Long id, String fromNumber, String toNumber ) {
		this.id = id;
		this.fromNumber = fromNumber;
		this.toNumber = toNumber;
	}

	public Long getId() {
		return id;
	}

	public void setId( Long id ) {
		this.id = id;
	}

	public String getFromNumber() {
		return fromNumber;
	}

	public void setFromNumber( String fromNumber ) {
		this.fromNumber = fromNumber;
	}

	public String getToNumber() {
		return toNumber;
	}

	public void setToNumber( String toNumber ) {
		this.toNumber = toNumber;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage( String message ) {
		this.message = message;
	}

	public String getProviderMessageId() {
		return providerMessageId;
	}

	public void setProviderMessageId( String providerMessageId ) {
		this.providerMessageId = providerMessageId;
	}

	public Integer getState() {
		return state;
	}

	public void setState( Integer state ) {
		this.state = state;
		this.stateChangeTime = new Date();
	}

	public Date getStateChangeTime() {
		return stateChangeTime;
	}

	public void setStateChangeTime( Date stateChangeTime ) {
		this.stateChangeTime = stateChangeTime;
	}

	public Date getProvidersIncomingTime() {
		return providersIncomingTime;
	}

	public void setProvidersIncomingTime( Date providersIncomingTime ) {
		this.providersIncomingTime = providersIncomingTime;
	}

	public Date getOurIncomingTime() {
		return ourIncomingTime;
	}

	public void setOurIncomingTime( Date ourIncomingTime ) {
		this.ourIncomingTime = ourIncomingTime;
	}

	public Integer getTypeOfMessage() {
		return typeOfMessage;
	}

	public void setTypeOfMessage( Integer typeOfMessage ) {
		this.typeOfMessage = typeOfMessage;
	}

	public String getTelenorEuRequest() {
		return telenorEuRequest;
	}

	public void setTelenorEuRequest( String telenorEuRequest ) {
		this.telenorEuRequest = telenorEuRequest;
	}

	public String getDataCoding() {
		return dataCoding;
	}

	public void setDataCoding( String dataCoding ) {
		this.dataCoding = dataCoding;
	}

	public String getTelenorESMC() {
		return telenorESMC;
	}

	public void setTelenorESMC( String telenorESMC ) {
		this.telenorESMC = telenorESMC;
	}

	public String getMessageBody() {
		return messageBody;
	}

	public void setMessageBody( String messageBody ) {
		this.messageBody = messageBody;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl( String url ) {
		this.url = url;
	}

	public byte[] getData() {
		return data;
	}

	public void setData( byte[] data ) {
		this.data = data;
	}

	public Set<PaymentInvoice> getPaymentInvoiceList() {
		return paymentInvoiceList;
	}

	public void setPaymentInvoiceList( Set<PaymentInvoice> paymentInvoiceList ) {
		this.paymentInvoiceList = paymentInvoiceList;
	}

	public Provider getProvider() {
		return provider;
	}

	public void setProvider( Provider provider ) {
		this.provider = provider;
	}

	public Service getService() {
		return service;
	}

	public void setService( Service service ) {
		this.service = service;
	}

	public String getMtsSessionId() {
		return mtsSessionId;
	}

	public void setMtsSessionId( String mtsSessionId ) {
		this.mtsSessionId = mtsSessionId;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals( Object object ) {
		if (!(object instanceof IncomingMessage)) {
			return false;
		}
		IncomingMessage other = (IncomingMessage) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals( other.id ))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return MessageFormat.format( "IncomingMessage[{0}]", this.id);
	}
}
